
// 
//  downloadergeneric.js
//  firefox
//  
//  Created by Zak on 2008-06-17.
//  Copyright 2008 Ant.com. All rights reserved.
// 


/**
 * Inherit from ParserInterface
 */
top.AntParserGeneric = function () {}
AntParserGeneric.prototype = new AntParser;
AntParser.prototype.constructor = AntParser;


/**
 * Parse page content and find flvs
 */
AntParserGeneric.prototype.isFlvAvailable = function ()
{
	var re = /(http:\/\/[^;><'"]+\.flv)(?=[?&"'\s])/gi;
	var html;
	
	try
	{
		html = this.getCurrentDocument().getElementsByTagName("html")[0].innerHTML;
	}
	catch (e)
	{
		return false;
	}
	this.flvArr = new AntArray();

	this.flvArr.fromArray(html.match(re));
	if (!this.flvArr)
		return false;
	this.flvArr = this.flvArr.uniq();
	
	return this.flvArr.length > 0;
}

/**
 * Interface implementation
 */
AntParserGeneric.prototype.getFlvArray= function ()
{
	if (this.isFlvAvailable())
	{
	    var loc = safeGet(this.getCurrentDocument(), "location");

		if (!loc)
			return false;

	    var host = AntLib.getSiteName(loc);
		var title = safeGet(this.getCurrentDocument(), "title");
		var arr = new AntArray();
		
		for (var i = 0; i < this.flvArr.length; i++)
		{
			var link =  new AntFlvLink({origin:host, url:this.flvArr[i], name:title, doc:this.getCurrentDocument()});
			arr.push(link);
		}
		return arr;
	}

    return null;
}
